package downloader;

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

public class URLDownloader extends TextFileDownloader {

	public URLDownloader(String url) {
		super(url);
	}
	public List<String> getLinesFromFile(){
		FileReader reader = null;
		BufferedReader bRead = null;
		List<String> lines = new ArrayList<String>();
		try{		
			reader = new FileReader(this.localFileName);
			bRead = new BufferedReader(reader);
			String buffer = null;
			while((buffer = bRead.readLine()) != null){
				lines.add(buffer);
			}
		}catch(Exception e){
			e.printStackTrace();
		}finally{
			if(bRead != null){
				try {
					bRead.close();
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
			if(reader!=null){
				try {
					reader.close();
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
		}
		return lines;
	}
	public static List<String> getURL(String url){
		List<String> urlList = new ArrayList<String>();
		URLDownloader downloader = new URLDownloader(url);
		downloader.download();
		urlList = downloader.getLinesFromFile();
		return urlList;
	}
	public static void main(String[] args) {
		System.out.println(URLDownloader.getURL("file:///c:/temp/input/url.txt"));
		System.out.println(URLDownloader.getURL("file:///c:/temp/input/string.txt"));
	}

}
